package com.example.instantmessage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.instantmessage.Contact;
import com.example.instantmessage.R;
import com.tencent.imsdk.v2.V2TIMFriendInfo;

import java.util.ArrayList;
import java.util.List;

public class ContactAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<V2TIMFriendInfo> contactList = new ArrayList<>();
    private Context context;

    public ContactAdapter(Context context,List< V2TIMFriendInfo> contactList) {

        this.context = context;
        this.contactList = contactList;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.contact_item,parent,false);
        ContactViewHolder contactViewHolder = new ContactViewHolder(view);
       return contactViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        V2TIMFriendInfo contact = contactList.get(position);
        ContactViewHolder contactViewHolder = (ContactViewHolder) holder;//???
        contactViewHolder.friendsId.setText(contact.getUserID());//???
    }

    @Override
    public int getItemCount() {
        return contactList.size();
    }

    static class ContactViewHolder extends RecyclerView.ViewHolder{//????
        public TextView friendsId;

        public ContactViewHolder(@NonNull View view) {
            super(view);
            friendsId = view.findViewById(R.id.friends_id_contact);
        }
    }
}
